package de.syfy.project.engine;

import de.syfy.project.engine.utils.RandomValues;
import de.syfy.project.engine.utils.Vector2D;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Timo
 */
public class ParticleContainer {
    public static float STANDARD_INTERVAL = 0.03125f;
    
    private Vector2D origin;
    private List<Particle> particles;
    
    public ParticleContainer(TextureLoader tl, int count, String texturePath, 
                                               Vector2D origin, float duration){
        this.origin = origin;
        particles = new ArrayList<Particle>();
        for(int i = 0; i < count;i++){
            Vector2D vel = new Vector2D(RandomValues.getRandomFloat(true)*
                                       5f,RandomValues.getRandomFloat(true)*5f);
            Vector2D acc = new Vector2D(RandomValues.getRandomFloat(true)*
                                   2.5f,RandomValues.getRandomFloat(true)*2.5f);
            particles.add(i, new Particle(origin,vel,acc,tl,texturePath,
                                                   duration,STANDARD_INTERVAL));
        }
    }
    
    public void run(){
        for(int i = 0; i < particles.size();i++){
            Particle p = particles.get(i);
            p.run();
            if(p.isDead()){
                particles.remove(i);
            }
        }
    }
    /*
     * TODO vel,acc,duration,interval müssen noch übergeben werden!
     */
    public void addParticle(TextureLoader tl, String texturePath){
        Vector2D vel = new Vector2D(RandomValues.getRandomFloat(true)*
                                       5f,RandomValues.getRandomFloat(true)*5f);
        Vector2D acc = new Vector2D(RandomValues.getRandomFloat(true)*
                                   2.5f,RandomValues.getRandomFloat(true)*2.5f);
        particles.add(new Particle(origin,vel,acc,tl,texturePath,2.5f,
                                                            STANDARD_INTERVAL));
    }
    
    public boolean isDead(){
        return particles.isEmpty();
    }
}
